﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Singleton<T> : MonoBehaviour where T : Singleton<T>
{
    private static T _instance;
    public static T Instance { get { return _instance; } }

    protected virtual void Awake()
    {
        if (_instance != null) { Destroy(gameObject); }
        else { _instance = (T)this; }
    }

    protected virtual void OnDestroy()
    {
        if (_instance == this) { _instance = null; }
    }

    public static bool IsCreated()
    {
        return _instance != null;
    }
}
